﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BTGISWASECO.DataLayer;
using BTGISWASECO.BusinessEntities;
using BTGISWASECO.BusinessLayer;

public partial class PresentationLayer_DefaultTab : System.Web.UI.Page
{
    DongHoTongBLL bll = new DongHoTongBLL();
    DMHuongDongChayDAL DMHuongDongChayDal = new DMHuongDongChayDAL();
    DongHoTongEntities DongHoTongEntities = new DongHoTongEntities();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["DataTable"] == "")
                Response.Redirect("../default.aspx");
            for (int i = DateTime.Now.Year; i >= 1990; --i)
            {
                ListItem iteml = new ListItem(i.ToString(), i.ToString());
                DListNamSX.Items.Add(iteml);
            }
            DListNamSX.SelectedValue = DongHoTongEntities.NamSanXuat.ToString();
            DongHoTongEntities = bll.GetDongHoTongEntitiesByID();
            txtObjectID.Value = DongHoTongEntities.OBJECTID.ToString();
            txtIDDongHo.Text = DongHoTongEntities.IDDongHo;
            this.txtDMA.Text = DongHoTongEntities.IDDMA;
            this.txtDMZ.Text = DongHoTongEntities.IDDMZ;

            foreach (var itemtc in DMTieuChuanDongHoDAL.GetList())
            {
                if (DongHoTongEntities.TieuChuanText.ToString().Trim() == itemtc.MoTa.ToString().Trim())
                    DongHoTongEntities.TieuChuan = itemtc.Ma;
                ListItem iteml = new ListItem(itemtc.MoTa.ToString(), itemtc.Ma.ToString());
                DListTieuChuan.Items.Add(iteml);
            }

            DListTieuChuan.SelectedValue = DongHoTongEntities.TieuChuan.ToString();

            foreach (var itemnsx in DMNhaSanXuatDAL.GetList())
            {
                if (DongHoTongEntities.NhaSanXuatText.ToString().Trim() == itemnsx.MoTa.ToString().Trim())
                    DongHoTongEntities.NhaSanXuat = itemnsx.Ma;
                ListItem iteml = new ListItem(itemnsx.MoTa.ToString(), itemnsx.Ma.ToString());
                DListNhaSX.Items.Add(iteml);
            }
            DListNhaSX.SelectedValue = DongHoTongEntities.NhaSanXuat.ToString();

            foreach (var itemnusx in DMNuocSanXuatDAL.GetList())
            {
                if (DongHoTongEntities.NuocSanXuatText.ToString().Trim() == itemnusx.MoTa.ToString().Trim())
                    DongHoTongEntities.NuocSanXuat = itemnusx.Ma;
                ListItem iteml = new ListItem(itemnusx.MoTa.ToString(), itemnusx.Ma.ToString());//
                DListNuocSX.Items.Add(iteml);
            }
            DListNuocSX.SelectedValue = DongHoTongEntities.NuocSanXuat.ToString();

            this.nSTDongHo.Text = DongHoTongEntities.SoThan.ToString();

            foreach (var itemvl in DMLoaiCauTaoDongHoDAL.GetList())
            {
                if (DongHoTongEntities.LoaiCTDHText.ToString().Trim() == itemvl.MoTa.ToString().Trim())
                    DongHoTongEntities.LoaiCTDH = itemvl.Ma;
                ListItem iteml = new ListItem(itemvl.MoTa.ToString(), itemvl.Ma.ToString());
                DListLoaiCTDH.Items.Add(iteml);
            }
            DListLoaiCTDH.SelectedValue = DongHoTongEntities.LoaiCTDH.ToString();

            foreach (var itemvl in DMLCCVHDongHoDAL.GetList())
            {
                if (DongHoTongEntities.LoaiCCVHText.ToString().Trim() == itemvl.MoTa.ToString().Trim())
                    DongHoTongEntities.LoaiCCVH = itemvl.Ma;
                ListItem iteml = new ListItem(itemvl.MoTa.ToString(), itemvl.Ma.ToString());
                DListLoaiCCVH.Items.Add(iteml);
            }
            DListLoaiCCVH.SelectedValue = DongHoTongEntities.LoaiCCVH.ToString();

            txtNgayLapDat.Text = DongHoTongEntities.NgayLapDat.ToString("dd/MM/yyyy");

            foreach (var itemc in DMLoaiMatSoDongHoDAL.GetList())
            {
                if (DongHoTongEntities.LoaiMatSoText.Trim() == itemc.MoTa.ToString().Trim())
                    DongHoTongEntities.LoaiMatSo = itemc.Ma;
                ListItem iteml = new ListItem(itemc.MoTa.ToString(), itemc.Ma.ToString());
                DListLoaiMatSo.Items.Add(iteml);
            }
            DListLoaiMatSo.SelectedValue = DongHoTongEntities.LoaiMatSo.ToString();

            this.txtMoTaViTri.Text = DongHoTongEntities.MoTaViTri.ToString();

            foreach (var itemnttsd in DMTinhTrangSDDAL.GetList())
            {
                if (DongHoTongEntities.TinhTrangText.ToString().Trim() == itemnttsd.MoTa.ToString().Trim())
                    DongHoTongEntities.TinhTrang = itemnttsd.Ma;
                ListItem iteml = new ListItem(itemnttsd.MoTa.ToString(), itemnttsd.Ma.ToString());
                DListTTSD.Items.Add(iteml);
            }
            DListTTSD.SelectedValue = DongHoTongEntities.TinhTrang.ToString();

            this.txtDonViDo.Text = DongHoTongEntities.DonViDo.ToString();

            this.dLuuLuongNN.Text = DongHoTongEntities.LuuLuongNN.ToString();

            this.dLuuLuongLN.Text = DongHoTongEntities.LuuLuongLN.ToString();

            this.dLuuLuongNN.Text = DongHoTongEntities.LuuLuongNN.ToString();

            this.dLuuLuongLN.Text = DongHoTongEntities.LuuLuongLN.ToString();

            this.dApLuc.Text=DongHoTongEntities.ApLuc.ToString();
            this.nSoLanThay.Text = DongHoTongEntities.SoLanThay.ToString();

            foreach (var itemntldv in DMLoaiDonViDAL.GetList())
            {
                if (DongHoTongEntities.DonViTCText != null)
                if (DongHoTongEntities.DonViTCText.ToString().Trim() == itemntldv.MoTa.ToString().Trim())
                    DongHoTongEntities.DonViTC = itemntldv.Ma;
                ListItem iteml = new ListItem(itemntldv.MoTa.ToString(), itemntldv.Ma.ToString());
                DListDonViTC.Items.Add(iteml);
            }
            DListDonViTC.SelectedValue = DongHoTongEntities.DonViTC.ToString();

            foreach (var itemntldv in DMLoaiDonViDAL.GetList())
            {
                if (DongHoTongEntities.DonViTKText != null)
                if (DongHoTongEntities.DonViTKText.ToString().Trim() == itemntldv.MoTa.ToString().Trim())
                    DongHoTongEntities.DonViTK = itemntldv.Ma;
                ListItem iteml = new ListItem(itemntldv.MoTa.ToString(), itemntldv.Ma.ToString());
                DListDonViTK.Items.Add(iteml);
            }
            DListDonViTK.SelectedValue = DongHoTongEntities.DonViTK.ToString();

            this.dDoChinhXac.Text = DongHoTongEntities.DoChinhXac.ToString();

            foreach (var itemntldv in DMLoaiDonViDAL.GetList())
            {
                if (DongHoTongEntities.DonViQLText != null)
                if (DongHoTongEntities.DonViQLText.ToString().Trim() == itemntldv.MoTa.ToString().Trim())
                    DongHoTongEntities.DonViQL = itemntldv.Ma;
                ListItem iteml = new ListItem(itemntldv.MoTa.ToString(), itemntldv.Ma.ToString());
                DListDonViQL.Items.Add(iteml);
            }
            DListDonViQL.SelectedValue = DongHoTongEntities.DonViQL.ToString();

            this.txtSoNha.Text = DongHoTongEntities.SoNha.ToString();
            this.txtMaDuong.Text = DongHoTongEntities.MaDuong.ToString();
            this.txtMaPhuong.Text = DongHoTongEntities.MaPhuong.ToString();
            this.txtMaQuan.Text = DongHoTongEntities.MaQuan;

            foreach (var itemkcv in DMKichCoDongHoDAL.GetList())
            {
                if (DongHoTongEntities.KichCoText != null)
                if (DongHoTongEntities.KichCoText.ToString().Trim() == itemkcv.MoTa.ToString().Trim())
                    DongHoTongEntities.KichCo = itemkcv.Ma;
                ListItem iteml = new ListItem(itemkcv.MoTa.ToString(), itemkcv.Ma.ToString());
                DListKichCo.Items.Add(iteml);
            }
            if (DongHoTongEntities.KichCo != null)
            DListKichCo.SelectedValue = DongHoTongEntities.KichCo.ToString();

            this.txtSoSeries.Text = DongHoTongEntities.SoSeries.ToString();

            this.nSLKPSuCo.Text = DongHoTongEntities.SoLanSuCo.ToString();

            this.txtTHDataLogger.Text = DongHoTongEntities.THDataLogger.ToString();

            foreach (var itemtsh in DMThuocSoHuuDAL.GetList())
            {
                if (DongHoTongEntities.ThuocSoHuuText.ToString().Trim() == itemtsh.MoTa.ToString().Trim())
                    DongHoTongEntities.ThuocSoHuu = itemtsh.Ma;
                ListItem iteml = new ListItem(itemtsh.MoTa.ToString(), itemtsh.Ma.ToString());
                DListThuocSoHuu.Items.Add(iteml);
            }
            DListThuocSoHuu.SelectedValue = DongHoTongEntities.ThuocSoHuu.ToString();

            this.txtNguoiCNC.Text = DongHoTongEntities.NguoiCNCuoi.ToString();
            this.txtNgayCNC.Text = DongHoTongEntities.NgayCNCuoi.ToString("dd/MM/yyyy");
            this.txtGhiChu.Text = DongHoTongEntities.GhiChu;
            this.txtMaHinhAnh.Text = DongHoTongEntities.IDHinhAnh;
        }//ThuocSoHuu
    }
    protected void btnCapNhat_Click(object sender, EventArgs e)
    {
        DongHoTongEntities bk = new DongHoTongEntities();
        DongHoTongDAL DongHoTongDAL = new DongHoTongDAL();
        //DongHoTongEntities DongHoTongEntities = new DongHoTongEntities(Convert.ToInt32(DListDonViTC.SelectedValue = DListDonViTC.SelectedValue!=""?DListDonViTC.SelectedValue:"0"),
        //    Convert.ToInt32(DListDonViGS.SelectedValue = DListDonViGS.SelectedValue!=""?DListDonViGS.SelectedValue:"0"), this.txtNguoiCNC.Text, DateTime.Parse(this.txtNgayCNC.Text.ToString()), this.txtGhiChu.Text, this.txtMaHinhAnh.Text);
        DongHoTongEntities DongHoTongEntities = new DongHoTongEntities(Convert.ToInt32(txtObjectID.Value),txtIDDongHo.Text, this.txtDMA.Text, this.txtDMZ.Text,
            Convert.ToInt32(DListTieuChuan.SelectedValue = DListTieuChuan.SelectedValue != "" ? DListTieuChuan.SelectedValue : "0"), Convert.ToInt32(DListNamSX.SelectedValue),
            Convert.ToInt32(DListNhaSX.SelectedValue = DListNhaSX.SelectedValue != "" ? DListNhaSX.SelectedValue : "0"),
            Convert.ToInt32(DListNuocSX.SelectedValue = DListNuocSX.SelectedValue != "" ? DListNuocSX.SelectedValue : "0"), Convert.ToInt32(this.nSTDongHo.Text) ,
			Convert.ToInt32(DListLoaiCTDH.SelectedValue = DListLoaiCTDH.SelectedValue != "" ? DListLoaiCTDH.SelectedValue : "0"), 
            Convert.ToInt32(DListLoaiCCVH.SelectedValue = DListLoaiCCVH.SelectedValue != "" ? DListLoaiCCVH.SelectedValue : "0"),
            Convert.ToInt32(DListLoaiMatSo.SelectedValue = DListLoaiMatSo.SelectedValue != "" ? DListLoaiMatSo.SelectedValue : "0"), DateTime.Parse(Request.Form.Get("txtNgayLapDat")),
			this.txtMoTaViTri.Text , Convert.ToInt32(DListTTSD.SelectedValue = DListTTSD.SelectedValue != "" ? DListTTSD.SelectedValue : "0") ,
            this.txtDonViDo.Text,Convert.ToDouble(this.dLuuLuongNN.Text) , Convert.ToDouble(this.dLuuLuongLN.Text) ,Convert.ToDouble(this.dApLuc.Text),Convert.ToInt32(this.nSoLanThay.Text),                   
            Convert.ToInt32(DListDonViTC.SelectedValue = DListDonViTC.SelectedValue != "" ? DListDonViTC.SelectedValue : "0") ,
			Convert.ToInt32(DListDonViTK.SelectedValue = DListDonViTK.SelectedValue != "" ? DListDonViTK.SelectedValue : "0") ,Convert.ToDouble(this.dDoChinhXac.Text),          
            Convert.ToInt32(DListDonViQL.SelectedValue = DListDonViQL.SelectedValue != "" ? DListDonViQL.SelectedValue : "0"), 
            this.txtSoNha.Text ,this.txtMaDuong.Text ,this.txtMaPhuong.Text , this.txtMaQuan.Text ,          
            DListKichCo.SelectedValue = DListKichCo.SelectedValue != "" ? DListKichCo.SelectedValue : "" , this.txtSoSeries.Text, Convert.ToInt32(this.nSLKPSuCo.Text) , this.txtTHDataLogger.Text ,      
            Convert.ToInt32(DListThuocSoHuu.SelectedValue = DListThuocSoHuu.SelectedValue != "" ? DListThuocSoHuu.SelectedValue : "0") ,
            this.txtNguoiCNC.Text ,  DateTime.Parse(Request.Form.Get("txtNgayCNC")) ,this.txtGhiChu.Text ,this.txtMaHinhAnh.Text);
        DongHoTongDAL.Update1(DongHoTongEntities);
        //DongHoTongDAL.Update(Convert.ToInt32(txtObjectID.Value), txtMaDoanOng.Text, txtDMA.Text, Convert.ToInt32(DListHDChay.SelectedValue), Convert.ToDouble(this.nChieuDai.Text));
      //  Response.Redirect("../default.aspx");
        ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script language='JavaScript'>alert('Cập nhật thành công'); window.location.href ='../Default.aspx';</script>");
    }
    protected void btnHuyBo_Click(object sender, EventArgs e)
    {
        Response.Redirect("../default.aspx");
    }
}